package DFS;

import java.util.ArrayList;
import java.util.List;

public class Solution77 {


    static int count;

    public static void main(String[] args) {
        System.out.println(combine(4, 4));
    }

    public static List<List<Integer>> combine(int n, int k) {
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = i + 1;
        }
        List<Integer> chain = new ArrayList<>();
        List<List<Integer>> res = new ArrayList<>();
        dfs(nums, k, 0, chain, res);
        System.out.println(count);
        return res;
    }

    public static void dfs(int[] nums, int k, int level, List<Integer> chain, List<List<Integer>> res) {
        //base
        if (chain.size() == k) {
            res.add(new ArrayList<>(chain));
            return;
        }
        //筛选节点
        //剪枝
        for (int i = level; i < nums.length; i++) {
            if (!chain.contains(nums[i])) {
                chain.add(nums[i]);
                dfs(nums, k, i + 1, chain, res);
                chain.remove(chain.size() - 1);
            }
        }
    }
}
